<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Fetch Tests</title>
  <link rel="stylesheet" href="/node_modules/mocha/mocha.css" />
</head>
<body>
  <div id="mocha"></div>
  <script>
    window.onerror = function(err) {
      var container = document.getElementById('mocha')
      var el = document.createElement('p')
      el.textContent = err.toString()
      el.style = 'color:#c00'
      container.insertBefore(el, container.firstChild)
    }
  </script>
  <script src="/node_modules/url-search-params/build/url-search-params.js"></script>
  <script src="/node_modules/chai/chai.js"></script>
  <script src="/node_modules/mocha/mocha.js"></script>
  <script>
    if (self.initMochaPhantomJS) {
      self.initMochaPhantomJS()
    }

    if (self.mocha && mocha.setup) {
      mocha.setup('tdd')
      self.assert = chai.assert
    } else {
      document.write('<p>Error: please run <code>make</code> to install dependencies and try again.</p>')
    }
  </script>

  <script src="/node_modules/promise-polyfill/promise.js"></script>
  <script src="/test/test.js"></script>
  <script src="/fetch.js"></script>

  <script>
    var runner = mocha.run();

    var failedTests = [];

    runner.on('end', function(){
      window.mochaResults = runner.stats;
      window.mochaResults.reports = failedTests;
    });

    runner.on('fail', function(test, err){
      function flattenTitles(test){
        var titles = [];
        while (test.parent.title){
          titles.push(test.parent.title);
          test = test.parent;
        }
        return titles.reverse();
      };

      failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
    });
  </script>
</body>
</html>
